<template>
    <div>
        <table>
            <tr>
                <td>登录名</td>
                <td><input type="text" v-model="data.name"></td>
            </tr>
            <tr>
                <td>密码</td>
                <td><input type="password" v-model="data.pwd"></td>
            </tr>
            <tr>
                <td>年龄</td>
                <td><input type="text" v-model="data.age"></td>
            </tr>
            <tr>
                <td>性别</td>
                <td>
                    <input type="radio" v-model="data.sex" name="" value="男" checked>男
                    <input type="radio" v-model="data.sex" name="" value="女">女
                </td>
            </tr>
            <tr>
                <td>图片</td>
                <td>
                    <input type="file" @change="tent">
                    <img :src="'https://localhost:7087'+data.img" alt="" style="width: 80px;height: 80px;">
                </td>
            </tr>
            <tr>
                <td><input type="button" value="添加" @click="Add"></td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';

const rount=useRouter()

const tent=(e:any)=>{
    var f=e.target.files[0];
    var fd=new FormData();
    fd.append('file',f);
    axios.post("https://localhost:7087/api/UpLog",fd).then(res=>{
        data.value.img=res.data;
    })
}

const data=ref({
  "id": 0,
  "name": "",
  "pwd": "",
  "age": 0,
  "sex": "",
  "img": ""
})

const Add=()=>{
    axios.post("https://localhost:7087/api/User/Add",data.value).then(res=>{
        if(res.data>0){
            alert('成功');
            rount.push({path:'/ShowView'})
            return;
        }
        else{
            alert('失败');
            return;
        }
    })
}


</script>

<style scoped>

</style>